package framework.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.WindowConstants;

import framework.controller.Controller;
import framework.controller.LobbyController;
import framework.controller.ServerController;
import framework.model.LobbyModel;
import framework.model.Model;
import framework.model.PlayersModel;
import framework.view.ChallengesView;
import framework.view.PlayersView;
import framework.view.UserInfoView;
import framework.view.View;

public class LobbyGUI extends GUI {

	private final String GUI_NAME = "Lobby v0.1";
	private final int GUI_WIDTH = 800, GUI_HEIGHT = 600;
	
	private PlayersView playersView;
	private ChallengesView challengesView;
	private UserInfoView userInfoView;
	
	private LobbyController lobbyController;
	private LobbyModel lobbyModel;
	
	/**
	 * Initialize LobbyGUI
	 * @method LobbyGUI (Constructor)
	 */
	public LobbyGUI() {
		this.setLobbyModel();
		this.setLobbyController();
		this.setViews();
		
		this.playersView.getController().handlePlayersRequest();
		this.playersView.getController().handleGamesRequest();
		
		this.initialize();
	};
	
	/**
	 * Initialize JFrame
	 * @method initialize
	 */
	private void initialize() {
		super.setResizable(false);
		super.setTitle(GUI_NAME);
		super.setSize(GUI_WIDTH, GUI_HEIGHT);
		super.setLocationRelativeTo(null);
		super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		super.setLayout(new BorderLayout(0,0));
		super.add(this.userInfoView, BorderLayout.NORTH);
		super.add(this.playersView, BorderLayout.EAST);
		super.add(this.challengesView, BorderLayout.CENTER);
		super.setVisible(true);	
	};

	/**
	 * Initialize LobbyModel
	 * @method setLobbyModel
	 */
	private void setLobbyModel() {
		this.lobbyModel = new LobbyModel();	
	};
	
	/**
	 * Initialize view and add the views to the model
	 * @method setViews
	 */
	private void setViews() {
		//PlayersView
		this.playersView = new PlayersView(this.lobbyModel,this.lobbyController);
		this.lobbyModel.addListener(this.playersView);
		//ChallengesView
		this.challengesView = new ChallengesView(this.lobbyModel, this.lobbyController);
		this.lobbyModel.addListener(this.challengesView);
		//UserInfoView
		this.userInfoView = new UserInfoView(this.lobbyModel);
		this.lobbyModel.addListener(this.userInfoView);
	};	
	
	/**
	 * Initialize LobbyController
	 * @method setLobbyController
	 */
	private void setLobbyController() {
		//LobbyController
		this.lobbyController = new LobbyController(this.lobbyModel);
	};
}
